package priv.lhy.authclient.controller;

import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * @author: lihy
 * date: 2019/11/13 16:04
 * description:
 */
@RestController
public class DemoController {

    @GetMapping("/product/{id}")
    public String getProduct(@PathVariable String id) {
        return "product id: " + id;
    }

    @GetMapping("/order/{id}")
    public String getOrder(@PathVariable String id) {
        return "order id: " + id;
    }

    @GetMapping("/getPrinciple")
    public OAuth2Authentication getPrinciple(OAuth2Authentication oAuth2Authentication, Principal principal){
        System.out.printf(oAuth2Authentication.getUserAuthentication().getAuthorities().toString());
        System.out.printf(oAuth2Authentication.toString());
        System.out.printf("principal.toString() " + principal.toString());
        System.out.printf("principal.getName() " + principal.getName());
        System.out.printf("authentication: " + oAuth2Authentication.getAuthorities().toString());

        return oAuth2Authentication;
    }
}
